var express = require('express');
var router = express.Router();
var User = require('../models/user.js');
var registerCache = require('../models/registerCache.js');
var error = require('../models/errorDescription.js');
router.post('/', function(req, res, next) {
    next();
});

// 验证号码是否已经注册
router.post('/number/', function(req, res, next) {
    var number = body.number;
    var type = number;
    User.find({"bind":number}, function (err, results) {
        if (err) {
            res.send(error.register.bind.applicationErr);
        } else if (results.length != 0) {
            res.send(error.register.bind.repeatErr);
            console.log('此号码已经注册');
        } else {
            registerCache.bind= number;
            registerCache.type = type;
            res.send(error.register.bind.success);
            console.log("此号码可以注册");
        }
    })
});

router.post('/identify/', function(error, results) {
    var code = body.sign;
    if (code == 1234) {
        res.send(error.bind.identify.success);
    } else {
        res.send(error.bind.identify.error);
    }
});
router.post('/resend/', function(error, results) {

});
router.post('/pn', function (req, res) {
    var password = body.password;
    var nickName = body.nickName;
    // 验证password
    if (password.length >= 6) {
        registerCache.password = password;
        registerCache.nickName = nickName;
        registerCache.save();
        res.send(error.register.nickName.success);
    } else {
        res.send(error.register.nickName.short);
        console.log('密码太短');
    }
});

